# -*- coding: utf-8 -*-
# filename: handle.py

import web
import json
from configcenter import configCenter
class prizeResult(object):
    def POST(self):
        try:
            web.header("Access-Control-Allow-Origin", "*")
            web.header('content-type','text/json')
            webData = web.input()
            prizeLevel = str(webData.prizeLevel)
            wd = web.input(winners=[])
            winners = wd.get('winners')
            print wd,winners,prizeLevel
            cc = configCenter()
            config = cc.getConfig()
            host = config.get("global", "ip")
            port = config.get("global", "port")
            user = config.get("global", "user")
            pw = config.get("global", "password")
            database = config.get("global", "database")
            db = web.database(dbn='mysql', host=host, port=int(port), user=user, pw=pw, db=database)
            for winner in winners:
                db.update('sign', where="mobile='"+winner+"'", prize_level=prizeLevel)
            result = {'result':True,'msg':winners}
            return json.dumps(result)
        except Exception as e:
            return e.args
